<template>
  <transition name="fade">
    <div class="confirm-box" v-if="isShow" ref="confirmDom">
      <div class="modal-bg" >
        <div class="confirm-content">
          <!-- 标题区域 -->
          <div class="title-content">
            <p>{{ confirmTitle || "提示" }}</p>
            <span
              v-show="isShowClose"
              class="close-btn"
              @click="handleConfirm('close')"
              >X</span
            >
          </div>
          <!-- 提示区域 -->
          <div class="msg-content">
            <img
              v-if="type === 'success'"
              src=""
              alt="error"
            />
            <img
              v-if="type === 'warning'"
              src=""
              alt="error"
            />
            <img
              v-if="type === 'error'"
              src=""
              alt="error"
            />
            <p class="tips-text">{{ confirmMsg }}</p>
          </div>
          <!-- 自定义配置按钮项 -->
          <div v-if="btnList.length" class="action-content">
            <div
              v-for="(btnItem, index) in btnList"
              :key="index"
              :class="btnItem.classType"
              class="btn"
              @click="handleConfirm(btnItem.funFlag)"
            >
              {{ btnItem.benText }}
            </div>
          </div>
          <!-- 默认按钮项目 -->
          <div v-else class="action-content">
            <div
              class="btn confirm"
              v-if="confirmBtnText"
              @click="handleConfirm('confirm')"
            >
              {{ confirmBtnText }}
            </div>
            <div
              class="btn other"
              v-if="otherBtnText"
              @click="handleConfirm('other')"
            >
              {{ otherBtnText }}
            </div>
            <div
              class="btn cancel"
              v-if="cancelBtnText"
              @click="handleConfirm('cancel')"
            >
              {{ cancelBtnText }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  data() {
    return {
      isShow: true,
      confirmTitle: "",
      confirmMsg: "",
      type: "success", // success, error, warning
      confirmBtnText: "确定",
      cancelBtnText: "取消",
      otherBtnText: "", // 冗余
      btnList: [], //  { classType: 'success', funFlag: 'suc', benText: 'confirm' }
      isShowClose: true,
    };
  },
  methods: {
    handleConfirm(status) {
      // console.log('in extend method handleConfirm:status', status);
    },
    closeConfirm() {
      this.isShow = false;
      if (this.$refs.confirmDom) this.$refs.confirmDom.remove();
    },
  },
};
</script>

<style lang="stylus" scoped>
@import '~./css/confirm'
.fade-enter-active, .fade-leave-active
  transition opacity 0.4s
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */
  opacity 0
</style>